#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 10;
bool st[N];
int n;
vector<int> now;
void print()
{
    for(auto e: now)
        cout << e << ' ';
    cout << endl;
}

void dfs(int x)
{
    if(x == n)
    {
        print();
        return;
    }
    for(int i = 1; i <= n; ++i)
    {
        if(!st[i])
        {
            st[i] = true;
            now.push_back(i);
            dfs(x + 1);
            now.pop_back();
            st[i] = false;
        }
    }
    
}



int main()
{
    cin >> n;
    dfs(0);
    return 0;
}